package com.buaa.homework02;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

public class AddressActivity extends AppCompatActivity {

    private Spinner province;
    private Spinner city;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_address);
        province = (Spinner)findViewById(R.id.province);
        city = (Spinner)findViewById(R.id.city);
        ArrayAdapter adapter1 = new ArrayAdapter(this,android.R.layout.simple_list_item_1,new String[]{"江苏省","山东省"});
        province.setAdapter(adapter1);
        ArrayAdapter adapter2 = new ArrayAdapter(this,android.R.layout.simple_list_item_1);
        if("江苏省"==province.getSelectedItem().toString()) {
            adapter2 = new ArrayAdapter(this,android.R.layout.simple_list_item_1,new String[]{"南京市","南通市"});

        }
        if("山东省"==province.getSelectedItem().toString()) {
            adapter2 = new ArrayAdapter(this,android.R.layout.simple_list_item_1,new String[]{"济南市","青岛市"});

        }
        city.setAdapter(adapter2);
    }

    public void finish(View view) {
        Intent intent = getIntent();
        intent.putExtra("address",province.getSelectedItem().toString()+city.getSelectedItem().toString());
        setResult(1,intent);
        finish();
    }
}
